# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/25 09:57 
@Author  : ZhangShenao 
@File    : app.py 
@Desc    : AI应用实体模型
"""

from sqlalchemy import (
    Column,
    UUID,
    String,
    Text,
    DateTime,
    PrimaryKeyConstraint,
    Index, text,
)

from internal.extension.db_extension import db


class App(db.Model):
    """AI应用基础模型类"""
    __tablename__ = "app"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="pk_app_id"),
        Index("idx_app_account_id", "account_id"),
    )

    # 使用server_default,即数据库的列默认值
    id = Column(UUID, nullable=False, server_default=text("uuid_generate_v4()"))
    account_id = Column(UUID)
    name = Column(String(255), nullable=False, server_default=text("''::character varying"))
    icon = Column(String(255), nullable=False, server_default=text("''::character varying"))
    description = Column(Text, nullable=False, server_default=text("''::character varying"))
    status = Column(String(255), nullable=False, server_default=text("''::character varying"))
    updated_at = Column(DateTime, nullable=False, server_default=text('CURRENT_TIMESTAMP(0)'),
                        server_onupdate=text('CURRENT_TIMESTAMP(0)'))
    created_at = Column(DateTime, nullable=False, server_default=text('CURRENT_TIMESTAMP(0)'))
